define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {  
                    type:3,
                    
                    user_info:{},
                    disabled:0,
                    page:1,
                    lastpage:0,
                    loading:0,
                    moneyLog:[],
                 
                };
            },
            el: '#pageCredits',
            created: function() {
                this.fetchData();
                
            },
            mounted: function() {
                    // console.log("123");
                    if (this.mounted == 1) {
                        return;
                    }
                    
                    var that = this ;
                    app.pager("#pageCredits",function(){
                       that.loadmoney();
                    });
                    this.mounted = 1;

            },
            methods: {
                fetchData: function() {
                    var _this = this;
                    this.user_info= app.getUserInfo();
                     this.getInfo();
                     this.loadmoney();
                    
                    
                },
                getInfo:function(){
                    var that = this;
                    app.get("api/user/info", {
                      user_id:this.user_info.user_id,
                      fields:"avatarUrl,user_id,last_update_time,nickname"
                    }, function (res) {
                      
                      if (res.code != 200) {
                        app.alert(res.msg);
                        return;
                      }
                       that.income=(res.data.income*0.99).toFixed(2);
                       that.fee = (res.data.income * 0.01).toFixed(2);
                       that.user_info=res.data;
                      
                    });  
                  },
               
                   unDoWithDraw:function(){
                    this.setViweType(3);
                    //setViweType(3)
                  },
                  //资金流水 
                  loadmoney:function(reload=0){
                    var that = this;
                    
                    if (reload==1){
                        this.loading=0;
                        this.page=1;
                        this.lastpage=0;
                        this.moneyLog=[];
                      
                    }
                    
                    if (this.loading==1 || this.lastpage==1){
                      return ;
                    }
                    var page = this.page;
                    this.loading=1;
                    app.get("api/credits_log/get", {
                      page: page,
                      limit:10,
                      order:'id desc'
                    },function(res){
                      that.loading = 0;
                      if (res.code != 200) {
                        app.alert(res.msg);
                        return;
                      }
                      if (res.data.list.length===0){
                        that.lastpage=1;
                      }
                      that.page++;
                      that.moneyLog = that.moneyLog.concat(res.data.list);
                    });
                  },
                 

                  showView:function(type){
                    this.setViweType(type );
                    
                  },
                  setViweType:function(id){
                    this.type = id;
                  }
 
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
